package com.aliyun.heiyu.powermaster.server.rotary.dao.impl;

import com.aliyun.heiyu.common.util.JdbcUtil;
import com.aliyun.heiyu.powermaster.proto.QueryRecommendTempReply;
import com.aliyun.heiyu.powermaster.server.rotary.contants.RecommendTempSqlContant;
import com.aliyun.heiyu.powermaster.server.rotary.dao.RecommendDAO;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.RecommendEntity;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: heiyu
 * @description: 推荐温度接口实现
 * @author: zhangshun
 * @create: 2020-02-17 17:43
 **/
public class RecommendDAOImpl implements RecommendDAO {
    @Override
    public Integer addRecommend(RecommendEntity recommendEntity) {
        Object[] obj = new Object[4];
        obj[0] = recommendEntity.getRecommend_temp();
        obj[1] = recommendEntity.getCurrent_temp();
        obj[2] = recommendEntity.getAir_id();
        obj[3] = new Date();
        Integer count = JdbcUtil.insert(RecommendTempSqlContant.ADD_RECOMMEND, obj);
        return count;
    }

    @Override
    public RecommendEntity queryRecommendById(int id) {
        Object[] obj = new Object[2];
        obj[0] = 1;
        obj[1] = id;
        return JdbcUtil.queryForBean(RecommendTempSqlContant.QUERY_RECOMMEND_ID, obj, RecommendEntity.class);
    }

    @Override
    public RecommendEntity queryRecommendNew() {
        return JdbcUtil.queryForBean(RecommendTempSqlContant.QUERY_RECOMMEND_NEW,null,RecommendEntity.class);
    }

    @Override
    public List<RecommendEntity> qyeryRecommends(QueryRecommendTempReply request) {
        Object[] obj = new Object[2];
       // obj[0] = request.getStartTime();
        //obj[1] = request.getEndTime();
        return JdbcUtil.queryForList(RecommendTempSqlContant.QUERY_RECOMMENDS_HOUR,null,RecommendEntity.class);
    }

    /**
     * 获取算法需要的服务器
     *
     * @return
     */
    @Override
    public Map<String,String> queryServersByPy() {
        String sql = "select collect_time,model_name,detail from ai_training.model_test order by collect_time desc limit 1";
        return JdbcUtil.queryForMap(sql, null);
    }
}
